package com.kk.base.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import lombok.Data;
import org.springframework.stereotype.Component;

/**
 * 分页信息封装类
 */
@Component
@Data
public class PageBean<T> {

    /**
     * 当前页码
     */
    private int currentPage = 1;

    /**
     * 每页显示数量，默认十条
     */
    private int pageSize = 2;

    /**
     * 总数量
     */
    private long total = 0;

    /**
     * 总页数
     */
    private int totalPage;

    private List<T> content;

    /**
     * 显示在页面可快速跳转的页码个数
     */
    private int showPageSize = 5;

    /**
     * 当前显示在页面快速跳转的页码
     */
    private List<Integer> currentShowPage = new ArrayList<>();

    public int getCurrentPage() {
        return currentPage;
    }

    public List<Integer> getCurrentShowPage() {
        //首先当前页往前显示currentShowPage页
        for (int i = currentPage - 1; i > 0; i--) {
            currentShowPage.add(i);
            if (i <= (currentPage - showPageSize)) {
                break;
            }
        }
        //接下来当前页往后显示currentShowPage页
        for (int i = currentPage; i <= totalPage; i++) {
            currentShowPage.add(i);
            if (i >= totalPage) {
                break;
            }
            if (i >= (showPageSize + currentPage)) {
                break;
            }
        }
        Collections.sort(currentShowPage);
        return currentShowPage;
    }
}
